package com.ruoyi.sys.energ.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.sys.energ.entity.TbEnergCaution;
import com.ruoyi.sys.energ.service.ITbEnergCautionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 能耗告警记录Controller
 * 
 * @author ruoyi
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/system/caution")
public class TbEnergCautionController extends BaseController
{
    @Autowired
    private ITbEnergCautionService tbEnergCautionService;

    /**
     * 查询能耗告警记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:caution:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbEnergCaution tbEnergCaution)
    {
        startPage();
        List<TbEnergCaution> list = tbEnergCautionService.selectTbEnergCautionList(tbEnergCaution);
        return getDataTable(list);
    }

    /**
     * 导出能耗告警记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:caution:export')")
    @Log(title = "能耗告警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbEnergCaution tbEnergCaution)
    {
        List<TbEnergCaution> list = tbEnergCautionService.selectTbEnergCautionList(tbEnergCaution);
        ExcelUtil<TbEnergCaution> util = new ExcelUtil<TbEnergCaution>(TbEnergCaution.class);
        util.exportExcel(response, list, "能耗告警记录数据");
    }

    /**
     * 获取能耗告警记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:caution:query')")
    @GetMapping(value = "/{ecId}")
    public AjaxResult getInfo(@PathVariable("ecId") Long ecId)
    {
        return AjaxResult.success(tbEnergCautionService.selectTbEnergCautionByEcId(ecId));
    }

    /**
     * 新增能耗告警记录
     */
    @PreAuthorize("@ss.hasPermi('system:caution:add')")
    @Log(title = "能耗告警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbEnergCaution tbEnergCaution)
    {
        return toAjax(tbEnergCautionService.insertTbEnergCaution(tbEnergCaution));
    }

    /**
     * 修改能耗告警记录
     */
    @PreAuthorize("@ss.hasPermi('system:caution:edit')")
    @Log(title = "能耗告警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbEnergCaution tbEnergCaution)
    {
        return toAjax(tbEnergCautionService.updateTbEnergCaution(tbEnergCaution));
    }

    /**
     * 删除能耗告警记录
     */
    @PreAuthorize("@ss.hasPermi('system:caution:remove')")
    @Log(title = "能耗告警记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ecIds}")
    public AjaxResult remove(@PathVariable Long[] ecIds)
    {
        return toAjax(tbEnergCautionService.deleteTbEnergCautionByEcIds(ecIds));
    }
}
